<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="110px">
      <el-form-item label="员工姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入员工姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="投保月份结束(废弃)" prop="insuranceEnd">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.insuranceEnd"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择投保月份结束(废弃)">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
      <el-form-item label="证件号码" prop="cardNum">
        <el-input
          v-model="queryParams.cardNum"
          placeholder="请输入证件号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="移动电话" prop="mobilePhone">
        <el-input
          v-model="queryParams.mobilePhone"
          placeholder="请输入移动电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="岗位" prop="job">
        <el-input
          v-model="queryParams.job"
          placeholder="请输入岗位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['employeeback:employeeback:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['employeeback:employeeback:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['employeeback:employeeback:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['employeeback:employeeback:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="employeebackList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="序号" type="index" align="center" width="50" />
      <el-table-column label="所在单位(二级)" align="center" prop="hroCompany.nameSecond" width="120" />
      <el-table-column label="所属合同" align="center" prop="agreementId" >
        <template slot-scope="scope">
          {{getAgreementName(scope.row.agreementId)}}
        </template>
      </el-table-column>
      <el-table-column label="员工编号" align="center" prop="code" width="110" />
      <el-table-column label="员工姓名" align="center" prop="name" >
        <!--        <template slot-scope="scope">
                  <el-link type="primary" @click="handleDetail(scope.row)">{{scope.row.name}}</el-link>
                </template>-->
      </el-table-column>

<!--      <el-table-column label="保单属性" align="center" prop="property" >-->
<!--        <template slot-scope="scope">-->
<!--          <dict-tag :options="dict.type.insurance_policy_property" :value="scope.row.property"/>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="生效时间" align="center" prop="insuranceStart" width="100"/>
      <el-table-column label="失效时间" align="center" prop="insuranceEnd" width="100"/>
<!--      <el-table-column label="投保月份" align="center" prop="insuranceStart" width="100">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.insuranceStart, '{y}-{m}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <!--      <el-table-column label="投保月份结束" align="center" prop="insuranceEnd" width="180">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ parseTime(scope.row.insuranceEnd, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="证件类型" align="center" prop="cardType" />
      <el-table-column label="证件号码" align="center" prop="cardNum" />
      <!--      <el-table-column label="民族" align="center" prop="nation" />-->
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="性别" align="center" prop="sex" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="户籍类型" align="center" prop="domicileType" />
      <el-table-column label="学历" align="center" prop="education" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.education" :value="scope.row.education"/>
        </template>
      </el-table-column>

      <el-table-column label="移动电话" align="center" prop="mobilePhone" />
      <el-table-column label="户籍地址" align="center" prop="domicileAddress" />
      <!--      <el-table-column label="备注" align="center" prop="remark" />-->
      <el-table-column label="岗位" align="center" prop="job" />
<!--      <el-table-column label="退回原因" align="center" prop="remark" />-->
      <el-table-column label="退回时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['employeeback:employeeback:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['employeeback:employeeback:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改退回员工对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="员工姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入员工姓名" />
        </el-form-item>
        <el-form-item label="员工编号" prop="code">
          <el-input v-model="form.code" placeholder="请输入员工编号" />
        </el-form-item>
        <el-form-item label="保单属性" prop="property">
          <el-input v-model="form.property" placeholder="请输入保单属性" />
        </el-form-item>
        <el-form-item label="投保月份" prop="insuranceStart">
          <el-date-picker clearable
            v-model="form.insuranceStart"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择投保月份">
          </el-date-picker>
        </el-form-item>
<!--        <el-form-item label="投保月份结束(废弃)" prop="insuranceEnd">-->
<!--          <el-date-picker clearable-->
<!--            v-model="form.insuranceEnd"-->
<!--            type="date"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            placeholder="请选择投保月份结束(废弃)">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
        <el-form-item label="证件号码" prop="cardNum">
          <el-input v-model="form.cardNum" placeholder="请输入证件号码" />
        </el-form-item>
        <el-form-item label="民族" prop="nation">
          <el-input v-model="form.nation" placeholder="请输入民族" />
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="学历" prop="education">
          <el-input v-model="form.education" placeholder="请输入学历" />
        </el-form-item>
        <el-form-item label="所在单位" prop="companyId">
          <el-input v-model="form.companyId" placeholder="请输入所在单位" />
        </el-form-item>
        <el-form-item label="移动电话" prop="mobilePhone">
          <el-input v-model="form.mobilePhone" placeholder="请输入移动电话" />
        </el-form-item>
        <el-form-item label="户籍地址" prop="domicileAddress">
          <el-input v-model="form.domicileAddress" placeholder="请输入户籍地址" />
        </el-form-item>
        <el-form-item label="删除状态" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除状态" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="岗位" prop="job">
          <el-input v-model="form.job" placeholder="请输入岗位" />
        </el-form-item>
        <el-form-item label="岗位类别" prop="category">
          <el-input v-model="form.category" placeholder="请输入岗位类别" />
        </el-form-item>
        <el-form-item label="联系地址" prop="contactAddress">
          <el-input v-model="form.contactAddress" placeholder="请输入联系地址" />
        </el-form-item>
        <el-form-item label="合同id" prop="agreementId">
          <el-input v-model="form.agreementId" placeholder="请输入合同id" />
        </el-form-item>
        <el-form-item label="是否经过决策" prop="isDecision">
          <el-input v-model="form.isDecision" placeholder="请输入是否经过决策" />
        </el-form-item>
        <el-form-item label="是否参与结算" prop="isJoinSettlement">
          <el-input v-model="form.isJoinSettlement" placeholder="请输入是否参与结算" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listEmployeeback, getEmployeeback, delEmployeeback, addEmployeeback, updateEmployeeback } from "@/api/employeeback/employeeback";
import {listAllCompanyAgreement} from "@/api/company_agreement/companyagreement";
export default {
  name: "Employeeback",
  dicts: ['education','employee_match_status','insurance_policy_property','sys_user_sex'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 退回员工表格数据
      employeebackList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      allCompanyAgreementList: [],
      // 查询参数
      queryParams: {
        orderByColumn:'m.create_time',
        isAsc:'desc',
        pageNum: 1,
        pageSize: 10,
        name: null,
        code: null,
        property: null,
        insuranceStart: null,
        insuranceEnd: null,
        cardType: null,
        cardNum: null,
        nation: null,
        age: null,
        sex: null,
        domicileType: null,
        education: null,
        companyId: null,
        mobilePhone: null,
        domicileAddress: null,
        status: null,
        auditStatus: null,
        job: null,
        category: null,
        contactAddress: null,
        agreementId: null,
        isDecision: null,
        isJoinSettlement: null,
        insucanceId:null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    if (this.$route.query.insucanceId) {
      this.queryParams.insucanceId = this.$route.query.insucanceId
    }
    this.getList();
    this.getCompanyAgreementList();
  },
  methods: {
    /** 查询退回员工列表 */
    getList() {
      this.loading = true;
      listEmployeeback(this.queryParams).then(response => {
        this.employeebackList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        code: null,
        property: null,
        insuranceStart: null,
        insuranceEnd: null,
        cardType: null,
        cardNum: null,
        nation: null,
        age: null,
        sex: null,
        domicileType: null,
        education: null,
        companyId: null,
        mobilePhone: null,
        domicileAddress: null,
        status: null,
        auditStatus: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        job: null,
        category: null,
        contactAddress: null,
        agreementId: null,
        isDecision: null,
        isJoinSettlement: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加退回员工";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getEmployeeback(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改退回员工";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateEmployeeback(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEmployeeback(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除退回员工编号为"' + ids + '"的数据项？').then(function() {
        return delEmployeeback(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('employeeback/employeeback/export', {
        ...this.queryParams
      }, `employeeback_${new Date().getTime()}.xlsx`)
    },
    // 获取客户合同列表
    getCompanyAgreementList(){
      let q= {};
      listAllCompanyAgreement(q).then(response => {
        this.allCompanyAgreementList = response;
      });
    },
    //表格中回显客户合同名称
    getAgreementName(id) {
      if (!id) {
        return null;
      }
      let name = null;
      this.allCompanyAgreementList.forEach((item, i) => {
        if (item.id == id){
          name = item.name;
        }
      });
      return name;
    },
  }
};
</script>
